package com.kugua.zfms.zif;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>TODO</p>
 * <p>
 * <PRE>
 * <BR>    修改记录
 * <BR>-----------------------------------------------
 * <BR>    修改日期         修改人          修改内容
 * </PRE>
 *
 * @author cuiyh9
 * @version 1.0
 * @Date Created in 2018年12月20日 16:21
 * @since 1.0
 */
public class ZifRoleWeight {

    public static final String SQL = "UPDATE zif_role SET weight = %s WHERE name = '%s';";
    public static void main(String[] args) {
        String filePath = "F:\\亲属排序表_20181220.txt";
        List<String> roleList = readCsv(filePath);
        int totalSize = roleList.size();
        for (String role : roleList) {
            System.out.println(String.format(SQL, totalSize * 1 ,role));
            totalSize--;
        }
    }

    // 读数据
    public static List<String> readCsv(String filepath) {

        File csv = new File(filepath); // CSV文件路径

        List<String> roleList = new ArrayList<>();
        try (InputStreamReader isr = new InputStreamReader(new FileInputStream(csv), "UTF-8"); BufferedReader br = new BufferedReader(isr);) {
            String line = "";
            while ((line = br.readLine()) != null) {
                if (line != null && line.trim().length() > 0 ) {
                    roleList.add(line.trim());
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

        return roleList;
    }
    // 分配权重
    //生成update语句
}
